﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WinAutomator.Library;
using WinAutomator.Library.InOut;
using WinAutomator.Library.MainType;

namespace WinAutomator.Plugin.BuildIns
{
    public class WAMessageBoxProcess : IProcess
    {
        public String Message { get; set; }
        List<VirtualConnector> _vconnector = new List<VirtualConnector>();

        public VirtualConnector VIn { get; protected set; }

        public WAMessageBoxProcess()
        {
            InStr = new Connector<string>(WAInOut.In, this);
            InStr.SetProcessData = setString;

            InListStr = new Connector<List<string>>(WAInOut.In, this);
            InListStr.SetProcessData = setListString;

            VIn = new VirtualConnector(WAInOut.In);
            VIn.AddConnector(InStr);
            VIn.AddConnector(InListStr);
            _vconnector.Add(VIn);
        }

        public IConnector Execute()
        {
            MessageBox.Show(Message);

            return (IConnector)Out;
        }

        public List<Type> getAcceptedType()
        {
            List<Type> type = new List<Type>() { typeof(String) };

            return type;
        }



        private void setListString(List<String> lstr)
        {
            StringBuilder sb = new StringBuilder();

            foreach (String str in lstr)
                sb.AppendLine(str);

            Message = sb.ToString();
        }

        private void setString(String str)
        {
            Message = str;
        }


        public List<VirtualConnector> getVirtualConnectors()
        {
            return _vconnector;
        }

        public List<VirtualConnector> getVirtualConnectors(WAInOut type)
        {
            List<VirtualConnector> tmp = new List<VirtualConnector>();

            foreach (VirtualConnector v in _vconnector)
                if (v.VirtualConnectorType == type)
                    tmp.Add(v);

            return tmp;
        }

        public Connector<String> InStr { get; set; }
        public Connector<List<String>> InListStr { get; set; }
        public Connector<String> Out { get; set; }
    }
}
